package com.wenwei.sharebox.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenwei.sharebox.R;
import com.wenwei.sharebox.bean.HomeHotGoodsBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/18.
 */
public class HomeSaleAdapter extends RecyclerView.Adapter<HomeSaleAdapter.MyViewHolder> {

    private Context mContext;
    private ArrayList<HomeHotGoodsBean> mList;
    private CallBack mCallBack;
    public interface CallBack {
        void onItemClick(int id);
    }
    public HomeSaleAdapter(CallBack callBack){
        this.mCallBack = callBack;
    }
    public void setSaleData(ArrayList<HomeHotGoodsBean> list) {
        this.mList = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        this.mContext = parent.getContext();
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_sale, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.itemTv.setText(mList.get(position).getShopName());
        Glide.with(mContext).load(mList.get(position).getImg()).error(R.drawable.banner).into(holder.itemImg);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.onItemClick(mList.get(position).getId());
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.item_img)
        ImageView itemImg;
        @Bind(R.id.item_tv)
        TextView itemTv;
        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
